home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / Hsoi's App Shell 1.0a4 / HAS Other Source / WASTE 1.3a4 Distribution / WASTE 1.3a4 / Source / WESelectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-16  |  5.5 KB  |  184 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WESelectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Routines for manipulating selector lookup tables
  6.  *
  7.  *  Copyright (c) 1993-1997 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14.  
  15. #include "WASTEIntf.h"
  16.  
  17. // MPW can't handle FIELD_DESC stuff (duh!)
  18.  
  19. #ifdef applec
  20.  
  21. //#error "hand-made selector tables not up-to-date!"
  22.  
  23. // this is **ugly** and will break if we change the declaration of WERec
  24.  
  25. WELookupTable _weMainSelectorTable[] = {
  26. { weRefCon,                     0x0078, 0x0004 },
  27. { wePort,                        0x0000, 0x0004 },
  28. { weText,                        0x0004, 0x0004 },
  29. { weCharToPixelHook,            0x00BC, 0x0004 },
  30. { weCharByteHook,                0x00C8, 0x0004 },
  31. { weCharTypeHook,                0x00CC, 0x0004 },
  32. { weClickLoop,                    0x009C, 0x0004 },
  33. { weCurrentDrag,                0x008C, 0x0004 },
  34. { weDrawTextHook,                0x00B4, 0x0004 },
  35. { weEraseHook,                    0x00D0, 0x0004 },
  36. { weFluxProc,                    0x00D4, 0x0004 },
  37. { weHiliteDropAreaHook,         0x00B0, 0x0004 },
  38. { weLineBreakHook,                0x00C0, 0x0004 },
  39. { weLineArray,                    0x0008, 0x0004 },
  40. { wePixelToCharHook,            0x00B8, 0x0004 },
  41. { weTSMPostUpdate,                0x00A8, 0x0004 },
  42. { weTSMPreUpdate,                0x00A4, 0x0004 },
  43. { weRunArray,                    0x0010, 0x0004 },
  44. { weScrollProc,                    0x00A0, 0x0004 },
  45. { weStyleTable,                    0x000C, 0x0004 },
  46. { weTSMDocumentID,                0x0080, 0x0004 },
  47. { weWordBreakHook,                0x00C4, 0x0004 },
  48. { weTranslateDragHook,            0x00AC, 0x0004 },
  49. #if WASTE_TRANSLUCENT_DRAGS
  50. { weTranslucencyThreshold,        0x00F0, 0x0004 },
  51. #endif
  52. #if WASTE_IC_SUPPORT
  53. { weURLHint,                    0x00F4, 0x0004 },
  54. #endif
  55. { 0,                     0, 0 }};
  56.  
  57. #if WASTE_OBJECTS
  58.  
  59. WELookupTable _weObjectHandlerSelectorTable[] = {
  60. { weClickHandler,        0x0010, 0x0004 },
  61. { weDrawHandler,        0x000C, 0x0004 },
  62. { weDisposeHandler,        0x0008, 0x0004 },
  63. { weNewHandler,            0x0004, 0x0004 },
  64. { weStreamHandler,      0x0014, 0x0004 },
  65. { weRefCon,             0x0018, 0x0004 },
  66. { 0,                     0, 0 }};
  67.  
  68. #endif  // WASTE_OBJECTS
  69.  
  70. #else
  71.  
  72. // proper way of defining selector tables
  73.  
  74. #define FIELD_OFFSET(FIELD, STRUCT)        (SInt16) &((STRUCT *) 0L)->FIELD
  75. #define FIELD_SIZE(FIELD, STRUCT)        (SInt16) sizeof(((STRUCT *) 0L)->FIELD)
  76. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  77.  
  78. WELookupTable _weMainSelectorTable[] = {
  79. { weRefCon,                 FIELD_DESC(refCon,                    WERec) },
  80. { wePort,                    FIELD_DESC(port,                      WERec) },
  81. { weText,                    FIELD_DESC(hText,                     WERec) },
  82. { weCharToPixelHook,        FIELD_DESC(charToPixelHook,           WERec) },
  83. { weCharByteHook,            FIELD_DESC(charByteHook,              WERec) },
  84. { weCharTypeHook,            FIELD_DESC(charTypeHook,              WERec) },
  85. { weClickLoop,                FIELD_DESC(clickLoop,                 WERec) },
  86. { weCurrentDrag,            FIELD_DESC(currentDrag,               WERec) },
  87. { weDrawTextHook,            FIELD_DESC(drawTextHook,              WERec) },
  88. { weEraseHook,                FIELD_DESC(eraseHook,                WERec) },
  89. { weFluxProc,                FIELD_DESC(fluxProc,                WERec) },
  90. { weHiliteDropAreaHook,        FIELD_DESC(hiliteDropAreaHook,        WERec) },
  91. { weLineBreakHook,            FIELD_DESC(lineBreakHook,             WERec) },
  92. { weLineArray,                FIELD_DESC(hLines,                    WERec) },
  93. { wePixelToCharHook,        FIELD_DESC(pixelToCharHook,           WERec) },
  94. { weTSMPostUpdate,            FIELD_DESC(tsmPostUpdate,             WERec) },
  95. { weTSMPreUpdate,            FIELD_DESC(tsmPreUpdate,              WERec) },
  96. { weRunArray,                FIELD_DESC(hRuns,                     WERec) },
  97. { weScrollProc,                FIELD_DESC(scrollProc,                WERec) },
  98. { weStyleTable,                FIELD_DESC(hStyles,                   WERec) },
  99. { weTSMDocumentID,            FIELD_DESC(tsmReference,              WERec) },
  100. { weWordBreakHook,            FIELD_DESC(wordBreakHook,            WERec) },
  101. { weTranslateDragHook,        FIELD_DESC(translateDragHook,         WERec) },
  102. #if WASTE_TRANSLUCENT_DRAGS
  103. { weTranslucencyThreshold,     FIELD_DESC(translucencyThreshold,    WERec) },
  104. #endif
  105. #if WASTE_IC_SUPPORT
  106. { weURLHint,                FIELD_DESC(hURLHint,                  WERec) },
  107. #endif
  108. { 0,                     0, 0 }};
  109.  
  110. #if WASTE_OBJECTS
  111.  
  112. WELookupTable _weObjectHandlerSelectorTable[] = {
  113. { weClickHandler,        FIELD_DESC(clickHandler,      WEOHTableEntry) },
  114. { weDrawHandler,        FIELD_DESC(drawHandler,       WEOHTableEntry) },
  115. { weDisposeHandler,        FIELD_DESC(freeHandler,       WEOHTableEntry) },
  116. { weNewHandler,            FIELD_DESC(newHandler,        WEOHTableEntry) },
  117. { weStreamHandler,      FIELD_DESC(streamHandler,     WEOHTableEntry) },
  118. { weRefCon,             FIELD_DESC(refCon,            WEOHTableEntry) },
  119. { 0,                     0, 0 }};
  120.  
  121. #endif    // WASTE_OBJECTS
  122.  
  123. #endif    // !applec
  124.  
  125. pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
  126. {
  127.     for ( ; table->selector != selector ; table++ )
  128.     {
  129.         if ( * (SInt32 *) &(table->desc) == 0L )
  130.         {
  131.             break;
  132.         }
  133.     }
  134.  
  135.     *desc = table->desc;
  136. }
  137.  
  138. pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  139. {
  140.     WEFieldDescriptor desc;
  141.  
  142.     _WELookupSelector(table, selector, &desc);
  143.  
  144.     if (desc.fLength == 0)
  145.     {
  146.         return weUndefinedSelectorErr;
  147.     }
  148.  
  149.     *info = * (SInt32 *) ((SInt32) structure + desc.fOffset);
  150.     return noErr;
  151. }
  152.  
  153. pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  154. {
  155.     WEFieldDescriptor desc;
  156.  
  157.     _WELookupSelector(table, selector, &desc);
  158.  
  159.     if (desc.fLength == 0)
  160.     {
  161.         return weUndefinedSelectorErr;
  162.     }
  163.  
  164.     * (SInt32 *) ((SInt32) structure + desc.fOffset) = *info;
  165.     return noErr;
  166. }
  167.  
  168. pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
  169. {
  170.     return _WEGetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  171. }
  172.  
  173. pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
  174. {
  175.     OSErr err;
  176.  
  177.     err = _WESetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  178.  
  179.     // the hook fields can never be nil, so replace any nil field with the default address
  180.     _WESetStandardHooks(hWE);
  181.  
  182.     return err;
  183. }
  184.